package com.ruoyi.jiajia.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JiajiaBanner;
import com.ruoyi.system.service.IJiajiaBannerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播图Controller
 * 
 * @author ruoyi
 * @date 2021-10-15
 */
@Controller
@RequestMapping("/jiajia/banner")
public class JiajiaBannerController extends BaseController
{
    private String prefix = "jiajia/banner";

    @Autowired
    private IJiajiaBannerService jiajiaBannerService;

    @RequiresPermissions("jiajia:banner:view")
    @GetMapping()
    public String banner()
    {
        return prefix + "/banner";
    }

    /**
     * 查询轮播图列表
     */
    @RequiresPermissions("jiajia:banner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaBanner jiajiaBanner)
    {
        startPage();
        List<JiajiaBanner> list = jiajiaBannerService.selectJiajiaBannerList(jiajiaBanner);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @RequiresPermissions("jiajia:banner:export")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaBanner jiajiaBanner)
    {
        List<JiajiaBanner> list = jiajiaBannerService.selectJiajiaBannerList(jiajiaBanner);
        ExcelUtil<JiajiaBanner> util = new ExcelUtil<JiajiaBanner>(JiajiaBanner.class);
        return util.exportExcel(list, "轮播图数据");
    }

    /**
     * 新增轮播图
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存轮播图
     */
    @RequiresPermissions("jiajia:banner:add")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaBanner jiajiaBanner)
    {
        return toAjax(jiajiaBannerService.insertJiajiaBanner(jiajiaBanner));
    }

    /**
     * 修改轮播图
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaBanner jiajiaBanner = jiajiaBannerService.selectJiajiaBannerById(id);
        mmap.put("jiajiaBanner", jiajiaBanner);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮播图
     */
    @RequiresPermissions("jiajia:banner:edit")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaBanner jiajiaBanner)
    {
        return toAjax(jiajiaBannerService.updateJiajiaBanner(jiajiaBanner));
    }

    /**
     * 删除轮播图
     */
    @RequiresPermissions("jiajia:banner:remove")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaBannerService.deleteJiajiaBannerByIds(ids));
    }
}
